#ifndef __PWHDR_STDLIB_HPP__
#define __PWHDR_STDLIB_HPP__

#include <purewell/types.hpp>

// STL
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <algorithm>

// C headers
#include <cstdlib>
#include <cstdio>
#include <cstring>

#ifdef __PW_HAVE_STDINT_H
#	include <stdint.h>
#endif//HAVE_STDINT_H

#ifdef __PW_HAVE_INTTYPE_H
#	include <inttype.h>
#endif//HAVE_INTTYPE_H

#ifdef __PW_HAVE_UNISTD_H
#	include <unistd.h>
#endif//HAVE_UNISTD_H

#include <errno.h>
#include <sys/types.h>

#ifdef __PW_HAVE_SYS_POLL_H
#	include <sys/poll.h>
#endif//HAVE_SYS_POLL_H

#ifdef __PW_HAVE_POLL_H
#	include <poll.h>
#endif//HAVE_POLL_H

#ifdef __PW_HAVE_FCNTL_H
#	include <fcntl.h>
#endif//HAVE_FCNTL_H

#ifdef __PW_HAVE_IOCTL_H
#	include <ioctl.h>
#endif//HAVE_IOCTL_H

#ifdef __PW_HAVE_SYS_IOCTL_H
#	include <sys/ioctl.h>
#endif//HAVE_SYS_IOCTL_H

#ifdef __PW_HAVE_DLFCN_H
#	include <dlfcn.h>
#endif//HAVE_DLFCN_H

#ifdef WIN32
#	include <winsock2.h>
#	include <ws2tcpip.h>
#	include <windows.h>
#	include <io.h>
#else
#	include <sys/socket.h>
#	include <netinet/in.h>
#	include <netinet/tcp.h>
#	include <arpa/inet.h>
#	include <netdb.h>
#endif//!WIN32

#ifdef __PW_HAVE_SYS_SELECT_H
#	include <sys/select.h>
#endif//!__PW_HAVE_SYS_SELECT_H

#ifdef __PW_HAVE_SYS_UN_H
#	include <sys/un.h>
#endif//__PW_HAVE_SYS_UN_H

#ifdef __PW_HAVE_SYS_MMAN_H
#	include <sys/mman.h>
#endif//HAVE_SYS_MMAN_H

#ifdef __PW_HAVE_SYS_EPOLL_H
#	include <sys/epoll.h>
#endif//HAVE_SyS_EPOLL_H

#ifdef __PW_HAVE_EPOLL_H
#	include <epoll.h>
#endif//HAVE_EPOLL_H

#ifdef __PW_HAVE_SEMAPHORE_H
#	include <semaphore.h>
#endif//HAVE_SEMAPHORE_H

#ifdef __PW_HAVE_MQUEUE_H
#	include <mqueue.h>
#endif//HAVE_MQUEUE_H

#if defined(__PW_HAVE_STRCASECMP)
#	define __PWSTRCMP_I(x,y)		strcasecmp(x,y)
#elif defined(__PW_HAVE_STRICMP)
#	define __PWSTRCMP_I(x,y)		stricmp(x,y)
#else
#	define __PWSTRCMP_I(x,y)		strcmp(x,y)
#endif//HAVE_STRCASECMP

#ifdef __PW_HAVE_SYS_STAT_H
#	include <sys/stat.h>
#endif//HAVE_SYS_STAT_H

#ifdef __PW_HAVE_STAT_H
#	include <stat.h>
#endif//HAVE_STAT_H

#ifdef __PW_HAVE_SYS_STATVFS_H
#	include <sys/statvfs.h>
#endif//HAVE_SYS_STATVFS_H

#ifdef __PW_HAVE_STATVFS_H
#	include <statvfs.h>
#endif//HAVE_STATVFS_H

#include <signal.h>

#ifdef __PW_HAVE_SYS_TIME_H
#	include <sys/time.h>
#endif//!__PW_HAVE_SYS_TIME_H

#ifdef __PW_HAVE_TIME_H
#	include <time.h>
#endif//!__PW_HAVE_TIME_H

#ifndef __PW_HAVE_SOCKLEN_T
typedef int socklen_t;
#endif//!HAVE_SOCKLEN_T

#ifndef __PW_HAVE_SOCKADDR_UN_T
struct sockaddr_un
{
	unsigned short int sun_family;
	char sun_path[purewell::PWSA_MAX_LEN - sizeof(unsigned short int)];
};
#endif//__PW_HAVE_SOCKADDR_UN_T

#ifndef __PW_HAVE_TIMEVAL_T
struct timeval
{
	int32_t		tv_sec;
	int32_t		tv_usec;
} timeval;
#endif//!__PW_HAVE_TIMEVAL_T

#define __PWERRNO_NOIMPL()	do { errno = ENOSYS; } while (false)

#include "liblog.hpp"

#ifdef WIN32
#	include <io.h>
#endif

#if defined(min)
#	undef min
#endif

#endif//!__PWHDR_STDLIB_HPP__

